$(document).ready(function(){

	var pages = document.body.getAttribute("page");
	
	var page = pages.split(".");
	var current_page = SEPRO.admin;
	for(var i=0; i<page.length; i++){
		current_page = current_page[page[i]];
	}
	current_page.init();
});

var SEPRO = {};
SEPRO.admin = {};

SEPRO.admin.index = {
	
	init: function(){
		$(".admin-tabs").tabs();
		this.init_paginators();
		this.add_event_for_product_menu();
		this.add_event_for_order_menu();
		this.add_event_for_payment_menu();
		this.add_event_for_payment_content();
	},
	
	add_event_for_payment_menu: function(){
		$("#payment-tab > .tab-left-panel > .tab-menu-ul > li > a").click(function(event){
			event.preventDefault();
			var index = $("#payment-tab > .tab-left-panel > .tab-menu-ul > li > a").index($(this)[0]);
			var liEls = $("#payment-tab > .tab-left-panel > .tab-menu-ul > li");
			for(var i = 0; i < liEls.length; i++){
				var curLiEl = liEls.eq(i);
				if(i == index){
					if(!curLiEl.hasClass("menu-selected")){
						curLiEl.attr("class", "menu-selected");
						curLiEl.find("img").attr("src", "images/list-arrow-orange.gif");
					}
					continue;
				}else{
					if(curLiEl.hasClass("menu-selected")){
						curLiEl.removeClass("menu-selected");
						curLiEl.find("img").attr("src", "images/list-arrow-gray.gif");
					}
				}
			}
		});	
	},
	
	add_event_for_order_menu: function(){
		$("#order-tab > .tab-left-panel > .tab-menu-ul > li > a").click(function(event){
			event.preventDefault();
			var index = $("#order-tab > .tab-left-panel > .tab-menu-ul > li > a").index($(this)[0]);
			var liEls = $("#order-tab > .tab-left-panel > .tab-menu-ul > li");
			for(var i = 0; i < liEls.length; i++){
				var curLiEl = liEls.eq(i);
				if(i == index){
					if(!curLiEl.hasClass("menu-selected")){
						curLiEl.attr("class", "menu-selected");
						curLiEl.find("img").attr("src", "images/list-arrow-orange.gif");
					}
					continue;
				}else{
					if(curLiEl.hasClass("menu-selected")){
						curLiEl.removeClass("menu-selected");
						curLiEl.find("img").attr("src", "images/list-arrow-gray.gif");
					}
				}
			}
		});	
	},
	
	add_event_for_payment_content: function(){
		$(".btn-list-payment").click(function(event){
			event.preventDefault();
			$(".added-payment-list").hide();
			$(".all-payment-list").show();
		});	
		$(".btn-add-payment").click(function(event){
			event.preventDefault();
			$(".all-payment-list").hide();
			$(".added-payment-list").show();
		});	
	},
	
	init_paginators: function(){
		$("#merchant-auth-paging-container").paginate({
			count:10,
    		start:1,
    		display:7,
   		 	border: false,
   		 	text_color: '#565555',
   		 	background_hover_color:'#f68833',
    		background_color: 'transparent',
		 				 
		});
		$("#refund-paging-container").paginate({
			count:10,
    		start:1,
    		display:7,
   		 	border: false,
   		 	text_color: '#565555',
   		 	background_hover_color:'#f68833',
    		background_color: 'transparent',		 
		});
	},
	
	add_event_for_product_menu: function(){
		
		$(".product-tab .tab-left-panel .tab-menu-ul a").click(function(event){
			event.preventDefault();
			var index = $(".product-tab .tab-left-panel .tab-menu-ul a").index($(this)[0]);
			var curEl = $(".product-tab .tab-left-panel .tab-menu-ul a").eq(index);
			var curClassVal = curEl.attr("class");
			var targetClassVal = curClassVal.substr(4, curClassVal.length);
			$("."+targetClassVal).show();
		});	
	}
}